﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.IDAL;
using AspNetCs.Model;
using System.Data;

namespace AspNetCs.SQLServerDAL
{
    public class LeaveInfoDAL:ILeaveInfo
    {
        public int Add(LeaveInfo model)
        {
            int count = 0;
            string cmdText = "insert into LeaveInfo values (@LeaveName,@Topic,@Email,@LinkPic,@LeaveContent,@LeaveTime,@Types,@ChannelID)";
            db.ParameterArry[] paras = new db.ParameterArry[8];

            paras[0].dbType = SqlDbType.VarChar;
            paras[0].objValue = model.LeaveName;
            paras[0].parName = "@LeaveName";

            paras[1].dbType = SqlDbType.VarChar;
            paras[1].objValue = model.Topic;
            paras[1].parName = "@Topic";

            paras[2].dbType = SqlDbType.VarChar;
            paras[2].objValue = model.Email;
            paras[2].parName = "@Email";

            paras[3].dbType = SqlDbType.VarChar;
            paras[3].objValue = model.LinkPic;
            paras[3].parName = "@LinkPic";

            paras[4].dbType = SqlDbType.Text;
            paras[4].parName = "@LeaveContent";
            paras[4].objValue = model.LeaveContent;

            paras[5].dbType = SqlDbType.DateTime;
            paras[5].parName = "@LeaveTime";
            paras[5].objValue = model.LeaveTime;

            paras[6].dbType = SqlDbType.Int;
            paras[6].parName = "@Types";
            paras[6].objValue = model.Types;

            paras[7].dbType = SqlDbType.Int;
            paras[7].parName = "@ChannelID";
            paras[7].objValue = model.ChannelID;

            db dbclass = new db();

            count = dbclass.ExcSql(cmdText,paras);
            return count;
        }

        public DataTable GetDataTable(string filter)
        {
            DataTable dataTable = new DataTable();
            string cmdText = "select *from LeaveInfo";
            string strWhere = " where {0}";
            if (string.IsNullOrEmpty(filter))
            {
                strWhere = "";
            }
            else
            {
                strWhere = string.Format(strWhere,filter);
            }
            cmdText += strWhere;
            db dbclass = new db();
            dataTable = dbclass.GetSql_DataTable(cmdText);
            return dataTable;
        }
    }
}
